package com.remenote.remenoteback.controller;

import com.remenote.remenoteback.entity.req.NoteRequest;
import com.remenote.remenoteback.entity.resp.ServerResponse;
import com.remenote.remenoteback.entity.vo.NoteVo;
import com.remenote.remenoteback.entity.vo.NotebookListVo;
import com.remenote.remenoteback.entity.vo.NotebookVo;
import com.remenote.remenoteback.service.NoteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/note")
@Slf4j
public class NoteController {
    @Autowired
    private NoteService noteService;

    @GetMapping("/notebooklist")
    public ServerResponse<NotebookListVo> listNotebooks(){
        return noteService.listNotebooks();
    }
    @GetMapping("/{notebookId}")
    public ServerResponse<List<NoteVo>> listNotes(@PathVariable Integer notebookId){
        return noteService.listNotes(notebookId);
    }
//    @GetMapping("/notedetail/{id}")
//    public ServerResponse<NoteVo> getNote(@PathVariable Integer id){
//        return noteService.getNote(id);
//    }
    @PostMapping("/allnotes")
    public  ServerResponse<List<NoteVo>> getAllNote(){
        return noteService.allNotes();}
    @PostMapping("/notedetail")
    public ServerResponse<NoteVo> getNoteByTitle(@RequestBody NoteRequest noteRequest){
        return noteService.getNote(noteRequest.getNotebookName(), noteRequest.getNoteTitle());
    }
    @PostMapping("/createnote")
    public ServerResponse<NoteVo> createNote(@RequestBody NoteRequest noteRequest){
        return noteService.createNote(noteRequest.getNoteTitle(),noteRequest.getNotebookId(),noteRequest.getContent());
    }
//    返回notebook列表
    @PostMapping("/createnotebook")
    public ServerResponse<NotebookListVo> createNotebook(@RequestBody NoteRequest noteRequest){
        return noteService.createNotebook(noteRequest.getNotebookName(),noteRequest.getNotebookDescription());
    }
    @PostMapping("/deletenote")
    public ServerResponse deleteNote(@RequestBody NoteRequest noteRequest){
        return noteService.deleteNote(noteRequest.getDelNoteId());
    }
    @PostMapping("/deletenotebook")
    public ServerResponse deleteNotebook(@RequestBody NoteRequest noteRequest){
        return noteService.deleteNotebook(noteRequest.getNotebookId());
    }
    @PostMapping("/updatenote")
    public ServerResponse updateNote(@RequestBody NoteRequest noteRequest){
        return noteService.saveNote(noteRequest);
    }
    @PostMapping("/search")
    public ServerResponse<List<NoteVo>> search(@RequestBody NoteRequest noteRequest){
        return noteService.search(noteRequest.getNoteTitle());
    }
    @PostMapping("/move")
    public ServerResponse moveNote(@RequestBody NoteRequest noteRequest){
        log.error(noteRequest.toString());
        return noteService.moveNote(noteRequest);
    }

}